const generateNextObj = (list) => {
  let newObj = {}, nextValue = ""
  const nextObj = (obj, key) => obj[key] = obj[key] || {}
  list.forEach((key, index) => nextValue = nextObj(index == 0 ? newObj : nextValue, key))
  return newObj
}

//循环生成多级对象
console.log(generateNextObj(["a", "b", "c"]))

//给多级对象属性赋值
const setNextObjValue = (obj, list, mKey, mValue) => {
  let nextItem = ""
  const nextObj = (obj, key) => obj[key] = obj[key]
  list.forEach((key, index) => nextItem = nextObj(index == 0 ? obj : nextItem, key))
  nextItem[mKey] = mValue
}
let originObj = {a: {b: {c: {k: 'bb'}}, e: "zz"}, d: 22}
//给c下面赋值一个属性值
setNextObjValue(originObj, ['a', 'b'], 'g', 'kk')
console.log(JSON.stringify(originObj))
